package com.activemq.boot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Destination;
import java.util.UUID;

@Service
@Slf4j
public class QueueProduce {
    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    private Destination queue;

    public void productMessage() {
        jmsMessagingTemplate.convertAndSend(queue, UUID.randomUUID().toString().substring(0, 6));
    }

    //    @Scheduled(cron = "0/3 * * * * *")
//    @Scheduled(fixedDelay = 3000) //3秒一次
    public void scheduleSend() {
        log.info("发送消息");
        productMessage();
    }
}
